namespace CGF
{
    public partial class PopupSucSold : UIComponentBase, IAwake<UILayer, bool>, IDestroy
    {
        public static void Open(string deviceId, string amount)
        {
            UIManagerComponent.instance.OpenUI<PopupSucSold>(UILayer.Normal, RootComponent.instance, true).SetInfo(deviceId, amount);
        }

        public static void Close()
        {
            UIManagerComponent.instance.CloseUI<PopupSucSold>();
        }

        public async void Awake(UILayer layer, bool isFloat)
        {
            await SpawnPrefab("Prefabs/GameUI/PopupSucSold", layer, isFloat);
            BindProperties(transform);

            ScaleIn(Dialog.transform);

            BtnClose.SetClick(Close);

            Particle.gameObject.SetActive(false);
            PlayEffect();
        }

        private async void PlayEffect()
        {
            await CTask.Wait(0.35f);
            Particle.gameObject.SetActive(true);
        }

        public async void SetInfo(string deviceId, string amount)
        {
            while (!Content) await CTask.Wait(0.1f);
            Content.text = $"{I18N_device}: {deviceId}\n<color=#000000>{I18N_income}</color>";
            Amount.text = $"{I18N.Currency} {amount}";
        }

        public override void OnDestroy()
        {
            base.OnDestroy();
        }

    }
}
